package com.kws.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.kws.common.core.domain.R;
import com.kws.common.log.annotation.Log;
import com.kws.common.log.enums.BusinessType;
import com.kws.system.domain.info.QueryMessageNotificationInfo;
import com.kws.system.domain.info.QueryMessageUserInfo;
import com.kws.system.domain.vo.CreateMessageNotificationRq;
import com.kws.system.domain.vo.QueryMessageUserRq;
import com.kws.system.domain.vo.UpdateMessageNotificationRq;
import com.kws.system.service.SysMessageManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <b>SysMessageManageController</b>
 *
 * @description: SysMessageManageController <br>
 * @date: 2024/11/5 15:00 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "消息管理模块")
@RestController
public class SysMessageManageController {
    private static final Logger logger = LoggerFactory.getLogger(SysMessageManageController.class);

    @Autowired
    private SysMessageManageService sysMessageManageService;

    @ApiOperation("分页查询消息通知列表")
    @GetMapping("/query/messageNotification/page")
    public R<Page<QueryMessageNotificationInfo>> queryMessageNotificationPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                              @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                              @RequestParam(required = false) String messageName){
        Page<QueryMessageNotificationInfo> pageInfo = sysMessageManageService.queryMessageNotificationPage(pageNum,pageSize,messageName);
        return R.ok(pageInfo);
    }

    @ApiOperation("新增消息通知")
    @Log(title = "新增消息通知", businessType = BusinessType.INSERT)
    @PostMapping("/create/messageNotification")
    public R createMessageNotification(@RequestBody CreateMessageNotificationRq rq){
        boolean status = sysMessageManageService.createMessageNotification(rq);
        return R.ok(status);
    }

    @ApiOperation("根据ID查询消息通知详情")
    @GetMapping("/query/messageNotification/byId")
    public R<QueryMessageNotificationInfo> queryMessageNotificationById(@RequestParam Long id){
        QueryMessageNotificationInfo info = sysMessageManageService.queryMessageNotificationById(id);
        return R.ok(info);
    }

    @ApiOperation("根据ID修改消息通知")
    @Log(title = "修改消息通知", businessType = BusinessType.UPDATE)
    @PostMapping("/update/messageNotification")
    public R updateMessageNotification(@RequestBody UpdateMessageNotificationRq rq){
        boolean status = sysMessageManageService.updateMessageNotification(rq);
        return R.ok(status);
    }

    @ApiOperation("根据ID删除消息通知")
    @Log(title = "删除消息通知", businessType = BusinessType.DELETE)
    @GetMapping("/delete/messageNotification/byId")
    public R deleteMessageNotificationById(@RequestParam Long id){
        boolean status = sysMessageManageService.deleteMessageNotificationById(id);
        return R.ok(status);
    }

    @ApiOperation("根据消息ID发布消息内容")
    @Log(title = "发布消息内容", businessType = BusinessType.PUBLISH)
    @GetMapping("/release/messageNotification/byId")
    public R releaseMessageNotificationById(@RequestParam Long id){
        boolean status = sysMessageManageService.releaseMessageNotificationById(id);
        return R.ok(status);
    }

    @ApiOperation("根据消息ID查询消息发送人员列表")
    @PostMapping("/query/messageUser/page")
    public R<PageInfo<QueryMessageUserInfo>> queryUserPage(@RequestBody QueryMessageUserRq rq){
        PageInfo<QueryMessageUserInfo> pageInfo = sysMessageManageService.queryUserPage(rq);
        return R.ok(pageInfo);
    }

}
